package com.jy.datapipeline.export.splitkey.factory;

import com.jy.datapipeline.common.constants.ExpConstants;
import com.jy.datapipeline.common.exception.GlobalException;
import com.jy.datapipeline.export.common.enums.impl.SplitKeyExecutorEnums;
import com.jy.datapipeline.export.splitkey.split.impl.AccurateSplit;
import com.jy.datapipeline.export.splitkey.split.impl.RoughSplit;
import com.jy.datapipeline.export.splitkey.split.Split;
import lombok.SneakyThrows;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @类名 SplitKeyFactory
 * @描述 可以用工厂模式获得两种分片对象【弃用】
 * @作者 白条君
 * @创建日期 2023/8/25 16:28
 * @版本 1.0
 */
@Deprecated
@Component
public class SplitKeyFactory {

    @Resource
    private AccurateSplit accurateSplit;

    @Resource
    private RoughSplit roughSplit;

    @SneakyThrows
    public Split createExecutor(int type) {
        if (type == SplitKeyExecutorEnums.ACCURATE_SPLIT_EXECUTOR.getCode()) {
            return accurateSplit;
        } else if (type == SplitKeyExecutorEnums.ROUGH_SPLIT_EXECUTOR.getCode()) {
            return roughSplit;
        } else {
            throw new GlobalException(ExpConstants.NULL_OBJECT);
        }
    }
}
